import Vue from "vue";
import App from "./App";
// import nodata from "./pages/commponent/public/nodata";
// import request from "utils/request.js"; //引入异步请求函数
//引入全局样式
// import "./static/css/public.css";
//引入vuex
import store from "./store";
//把vuex定义成全局组件
Vue.prototype.$store = store;
Vue.config.productionTip = false;
// Vue.prototype.request = request.request; //挂载到全局
// Vue.component("nodata", nodata);
Vue.mixin({
    methods: {
        setData: function(obj, callback) {
            let that = this;
            const handleData = (tepData, tepKey, afterKey) => {
                tepKey = tepKey.split(".");
                tepKey.forEach((item) => {
                    if (tepData[item] === null || tepData[item] === undefined) {
                        let reg = /^[0-9]+$/;
                        tepData[item] = reg.test(afterKey) ? [] : {};
                        tepData = tepData[item];
                    } else {
                        tepData = tepData[item];
                    }
                });
                return tepData;
            };
            const isFn = function(value) {
                return typeof value == "function" || false;
            };
            Object.keys(obj).forEach(function(key) {
                let val = obj[key];
                key = key.replace(/\]/g, "").replace(/\[/g, ".");
                let front, after;
                let index_after = key.lastIndexOf(".");
                if (index_after != -1) {
                    after = key.slice(index_after + 1);
                    front = handleData(that, key.slice(0, index_after), after);
                } else {
                    after = key;
                    front = that;
                }
                if (front.$data && front.$data[after] === undefined) {
                    Object.defineProperty(front, after, {
                        get() {
                            return front.$data[after];
                        },
                        set(newValue) {
                            front.$data[after] = newValue;
                            that.$forceUpdate();
                        },
                        enumerable: true,
                        configurable: true,
                    });
                    front[after] = val;
                } else {
                    that.$set(front, after, val);
                }
            });
            isFn(callback) && this.$nextTick(callback);
        },
    }
});

/* zwhq */
import uView from '@/uni_modules/uview-ui'
Vue.use(uView);
// 自定义工具
import util from "@/utils/util.js";
for (let key in util) {
	Vue.prototype[key] = util[key];
}
/* zwhq */
App.mpType = "app";
const app = new Vue({
    ...App,
    store,
});
app.$mount();
